package com.example.myapplication.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication.R;
import com.example.myapplication.bean.MoneyData;
import com.example.myapplication.util.MyDateUtil;
import com.example.myapplication.util.RandomUtil;

import java.util.Date;

/**
 * @author ：xiongwei
 * @date ：Created in 2021/7/18 16:23
 */
public class ShunDeActivity extends AppCompatActivity {

    private final String TRANSACTION_HEAD = "4200001213";
    private final String MERCHANT_HEAD = "159510006363";

    TextView moneyText;
    TextView timeText;
    TextView transactionNumberText;
    TextView merchantNumberText;
    TextView merchantNumberSecondText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shunde_mi10);

        moneyText = findViewById(R.id.shunde_money_text);
        moneyText.setOnClickListener(moneyClickListener);
        timeText = findViewById(R.id.shunde_time_text);

        MoneyData moneyData = (MoneyData) getIntent().getSerializableExtra("moneyData");
        moneyText.setText("-" + moneyData.getMoney());
        timeText.setText(moneyData.getStartTime());
        String day = getDate(moneyData.getStartTime());

        transactionNumberText = findViewById(R.id.shunde_transaction_number_text);
        merchantNumberText = findViewById(R.id.shunde_merchant_number_text);
        merchantNumberSecondText = findViewById(R.id.shunde_merchant_number_second_text);

        transactionNumberText.setText(getTransactionNumber(day));
        merchantNumberText.setText(getMerchant(day));
        merchantNumberSecondText.setText(getMerchantSecondRandom().toString());

    }

    private String getDate(String time) {
        Date date = MyDateUtil.stringtoDate(time, MyDateUtil.FORMAT_TWO);
        return MyDateUtil.dateToString(date, MyDateUtil.DATE_FORMAT_yyyyMMdd);
    }

    private String getTransactionNumber(String time) {
        StringBuilder stringBuilder = new StringBuilder(TRANSACTION_HEAD);
        stringBuilder.append(time);
        stringBuilder.append(getTransactionRandom().toString());
        stringBuilder.append(getTransactionRandom().toString());
        return stringBuilder.toString();
    }

    private String getMerchant(String time) {
        StringBuilder stringBuilder = new StringBuilder(MERCHANT_HEAD);
        stringBuilder.append(time);
        stringBuilder.append(getMerchantRandom().toString());
        stringBuilder.append(getMerchantRandom().toString());
        return stringBuilder.toString();
    }

    private Integer getMerchantSecondRandom() {
        int max = 99, min = 10;
        return  RandomUtil.getRandom(max, min);
    }

    private Integer getMerchantRandom() {
        int max = 9999, min = 1000;
        return  RandomUtil.getRandom(max, min);
    }

    private Integer getTransactionRandom() {
        int max = 99999, min = 10000;
        return RandomUtil.getRandom(max, min);
    }


    /**
     * 金钱跳转到主页面
     */
    View.OnClickListener moneyClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(ShunDeActivity.this, MainActivity.class);
            startActivity(intent);
        }
    };


}
